var SessionManager = (function (mod) {

    // Session类
    function Session(a, b) {
        if (b === undefined) {
            this.key = a.key;
            this.list = a.list;
        } else {
            this.key = a; // 保存Session的时间
            this.list = eval(b); // 上次未关闭网页
        }

        /*
         * 清除已经打开过的链接（reopend=true的链接） 可以节省一些不必要的空间，避免链接列表过大
         */
        this.ClearOpenedLinks = function () {
            this.list = this.list.filter(function (element) {
                return !element.reopend;
            });
        };

        this.SaveAsFile = function () {
            var content = JSON.stringify(this);
            var blob = new Blob([content], {
                type: "text/plain;charset=utf-8"
            });
            saveAs(blob, this.key + '.txt');
        };

        this.toString = function () {
            return JSON.stringify(this.list);
        };

        this.count = function () {
            return this.list.length;
        };
    }

    mod.Session = Session;

    return mod;

})(window.SessionManager || {});